package pl.lodz.p.browarex.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import pl.lodz.p.browarex.base.BaseCrudDao;
import pl.lodz.p.browarex.model.Product;

@Repository
public class ProductDAO extends BaseCrudDao<Product, Long> {

	public ProductDAO(Class<Product> type) {
		super(type);
	}

	public ProductDAO() {
		super(Product.class);
	}

	public Product loadByProductID(String productID) {
		Criteria criteria = getSession().createCriteria(type);
		criteria.add(Restrictions.eq("productID", productID));
		return (Product) criteria.uniqueResult();
	}
	
	public List<Product> findProductByName(String value) {
		Criteria criteria = getSession().createCriteria(type);
		criteria.add(Restrictions.like("productName","%" + value + "%").ignoreCase());
		return (List<Product>) criteria.list();
	}

	public List<Product> findProductByManufacture(String manufacture) {
		Criteria criteria = getSession().createCriteria(type);
		criteria.add(Restrictions.like("manufacturer", "%" + manufacture + "%")
				.ignoreCase());
		return (List<Product>) criteria.list();
	}
}
